<script setup lang="ts">
import { invoke } from "@tauri-apps/api/core";
import * as xcomService from "@/assets/api/xcomservice_0_0_1";
import { reactive } from "vue";
import { load_electricity_data_analysis_service_dxc, load_user_dxc, load_xcom_service_dxc } from "./dxc";

const data = reactive<{
  isInit: boolean
}>({
  isInit: false
});

// 让页面进来，就打开控制台，方便调试
invoke("open_devtools");

const connectToDataSourceNode = async () => {
  const res = await xcomService.BuildChannel({
    node_url: "dxm://127.0.0.1:9090",
    is_keep: true
  });

  console.log(res);
};


// 初始化 xPort
const onInitxPort = async () => {
  const is_init = await invoke("is_init_xport");
  if (!is_init) {
    // 启动 xport
    await invoke("boot_xport");
    await load_xcom_service_dxc();
    console.log("加载数据分析组件。。。")
    await load_user_dxc();
    await load_electricity_data_analysis_service_dxc();
    await connectToDataSourceNode();
  }
  data.isInit = true
};
onInitxPort()

</script>
<template>
  <!-- 保留路由组件 -->
  <router-view v-if="data.isInit" />
</template>
<style lang="scss" scoped>
</style>